package com.lby.controller;


import com.lby.domain.SsmUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.lby.service.SsmService;

import java.util.List;

//controller层的注解
@Controller

@RequestMapping("/ssm")
public class UserController {

    @Autowired //交给 Spring
    private SsmService ssmService;

    /**
     *  插入数据的
     * @param ssmUser
     * @return
     */
    @RequestMapping(value = "/save",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String save(SsmUser ssmUser){
        ssmService.insertUser(ssmUser);
        return "保存成功";
    }

    /**
     *  查询的
     * @return
     */
    @RequestMapping("selectUser")
    public ModelAndView selectUser(){
        List<SsmUser> ssmUsers = ssmService.selectSsmUser();
        ModelAndView modelAndView = new ModelAndView();
       modelAndView.addObject("ssmUser",ssmUsers);
       modelAndView.setViewName("ssm");
       return modelAndView;
    }
}
